/**\file gr_streamsignature.cpp Stream signature
*
*/
#include "gr_streamsignature.h"
#include "gr_shims.h"

namespace gr{

size_t streamTypeSize(StreamType type)
{
    size_t size = 0;
    switch(type)
    {
        case STREAM_FLOAT4: size = 4 * sizeof(float); break;
        default: break;
    }
    return size;
}

StreamChannelInfo streamChannelInfo(StreamType channelType, uint32_t offset, const char* name)
{
    StreamChannelInfo s = {channelType, offset, std::string(name)};
    return s;
}

const size_t* StreamSignature::offsetOfChannel(const std::string& name)
{
    size_t* offset = nullptr;
    auto info = find(channels_, 
        [&name](const StreamChannelInfo& info){return areEqual(info.name,name);});
    if(info) offset = & info->offset;
    return offset;
}

const StreamType* StreamSignature::typeOfChannel(const std::string& name)
{
    StreamType* channelType = nullptr;
    auto info = find(channels_, 
        [&name](const StreamChannelInfo& info){return areEqual(info.name,name);});
    if(info) channelType = & info->channelType;
    return channelType;
}

const size_t StreamSignature::sizeOfChannel(const std::string& name)
{
    size_t size = 0;
    const StreamType* type = typeOfChannel(name);
    if(type) size = streamTypeSize(*type);
    return size;
}

}
